import request from "@/utils/request";

const base_url = "/admin/product/category";

export default {
  // 根据parentId获取下级节点
  FindCategoryByParentId: parentId => {
    return request({
      url: `${base_url}/findByParentId/${parentId}`,
      method: "get"
    });
  },
  // 获取分类数据
  findAll: () => {
    return request({
      url: `${base_url}/list`,
      method: "GET"
    });
  },

  // 商品分类操作：有ID更新，无ID新增
  operate: category => {
    return request({
      url: `${base_url}/operate`,
      method: "POST",
      data: category
    });
  },

  // 删除商品分类
  removeById: (id, removeImg) => {
    return request({
      url: `${base_url}/remove`,
      method: "DELETE",
      data: { id, removeImg }
    });
  },

  // 批量删除商品分类
  removeBatch: ids => {
    return request({
      url: `${base_url}/remove/batch`,
      method: "DELETE",
      data: ids
    });
  },

  // 导出为excel
  exportData: () => {
    return request({
      url: `${base_url}/export-data`,
      method: "GET",
      responseType: "blob"
    });
  },
  // excel导入
  importData: id => {
    return request({
      url: `${base_url}/importData`,
      method: "POST"
    });
  }
};
